﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PM.Entity;
using System.Data;

namespace PM.Services
{
    
   public static class BankDepositServies
    {
       private static BankDeposit GetBankDepositFromDataReader(IDataReader dataReader)
        {
            BankDeposit retVal = null;
            if (dataReader != null && !dataReader.IsClosed)
            {
                retVal = new BankDeposit();
                retVal.BankId = dataReader["BANK_ID"].ToString();
                retVal.AccNo = dataReader["ACC_NO"].ToString();
                retVal.AccType = dataReader["ACC_TYPE"].ToString();                        
                DateTime invDate = DateTime.MinValue;
                if (DateTime.TryParse(dataReader["INVEST_DATE"].ToString(), out invDate))
                {
                    retVal.InvestDate = invDate;
                }
                decimal invValue = 0.00M;
                decimal.TryParse(dataReader["INVEST_VALUE"].ToString(), out invValue);
                retVal.InvestValue = invValue;             
                DateTime maturityDate = DateTime.MinValue;
                if (DateTime.TryParse(dataReader["MATURITY_DATE"].ToString(), out maturityDate))
                {
                    retVal.MaturityDate = maturityDate;
                }              
                decimal rate = 0.00M;
                decimal.TryParse(dataReader["RATE"].ToString(), out rate);
                retVal.Rate = rate;

                int active = 0;
                int.TryParse(dataReader["ACTIVE"].ToString(), out active);
                if (active == 1)
                {
                    retVal.Active = true;
                }
                else
                {
                    retVal.Active = false;
                }
            }
            return retVal;
        }
    }
}
